package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.Company;

/**
 * Session Bean implementation class EaoUser
 */
@Stateless(mappedName = "eaoCompany")
@LocalBean
public class EaoCompany {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoCompany() {
        // TODO Auto-generated constructor stub
    }
    

    public Company find(int id) {
        return em.find(Company.class, id);
    }

    public List<Company> list() {
    	return em.createQuery("SELECT c FROM Company c", Company.class).getResultList();
    }

    public void create(Company company) {
        	em.persist(company);
    }

    public void update(Company company) {
        em.merge(company);
    }

    public void delete(Company company) {
        em.remove(em.contains(company) ? company : em.merge(company));
    }

}
